
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server Compact Edition
-- --------------------------------------------------
-- Date Created: 04/13/2012 11:35:23
-- Generated from EDMX file: E:\mydata\东方育儿\DFYE.Web\DFYE.Web\Models\entityDB.edmx
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- NOTE: if the constraint does not exist, an ignorable error will be reported.
-- --------------------------------------------------

    ALTER TABLE [document] DROP CONSTRAINT [FK_documentdocumentType];
GO
    ALTER TABLE [studentDaily] DROP CONSTRAINT [FK_studentstudentDaily];
GO
    ALTER TABLE [studentDaily] DROP CONSTRAINT [FK_studentDailystudentDailyType];
GO
    ALTER TABLE [studentReply] DROP CONSTRAINT [FK_studentstudentReply];
GO
    ALTER TABLE [student] DROP CONSTRAINT [FK_studentstudentClass];
GO
    ALTER TABLE [manageUser] DROP CONSTRAINT [FK_manageUseruserType];
GO
    ALTER TABLE [studentViewLog] DROP CONSTRAINT [FK_studentstudentViewLog];
GO
    ALTER TABLE [channel] DROP CONSTRAINT [FK_channelchannel];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- NOTE: if the table does not exist, an ignorable error will be reported.
-- --------------------------------------------------

    DROP TABLE [document];
GO
    DROP TABLE [documentType];
GO
    DROP TABLE [guestBook];
GO
    DROP TABLE [manageUser];
GO
    DROP TABLE [SiteLibrary];
GO
    DROP TABLE [student];
GO
    DROP TABLE [studentClass];
GO
    DROP TABLE [studentDaily];
GO
    DROP TABLE [studentDailyType];
GO
    DROP TABLE [studentReply];
GO
    DROP TABLE [userType];
GO
    DROP TABLE [studentViewLog];
GO
    DROP TABLE [channel];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'document'
CREATE TABLE [document] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [title] nvarchar(200)  NOT NULL,
    [content] nvarchar(4000)  NULL,
    [ext] nvarchar(1000)  NULL,
    [able] bit  NOT NULL,
    [rank] int  NULL,
    [documentTypeID] int  NOT NULL,
    [datetime] datetime  NOT NULL,
    [channelTypeID] int  NOT NULL
);
GO

-- Creating table 'documentType'
CREATE TABLE [documentType] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [name] nvarchar(50)  NOT NULL,
    [value] nvarchar(1000)  NULL,
    [exp] nvarchar(4000)  NULL,
    [able] bit  NOT NULL,
    [rank] int  NULL,
    [requirement] bit  NOT NULL
);
GO

-- Creating table 'guestBook'
CREATE TABLE [guestBook] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [name] nvarchar(50)  NULL,
    [content] nvarchar(4000)  NULL,
    [datetime] datetime  NOT NULL,
    [ip] nvarchar(15)  NULL,
    [replyDatetime] datetime  NULL,
    [replyContent] nvarchar(4000)  NULL,
    [able] bit  NOT NULL
);
GO

-- Creating table 'manageUser'
CREATE TABLE [manageUser] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [loginname] nvarchar(20)  NOT NULL,
    [password] nvarchar(32)  NOT NULL,
    [username] nvarchar(20)  NULL,
    [userpower] nvarchar(50)  NULL,
    [dept] nvarchar(6)  NULL,
    [datetime] datetime  NULL,
    [able] bit  NOT NULL,
    [tearcher] bit  NOT NULL,
    [bak] nvarchar(4000)  NULL,
    [requirement] bit  NOT NULL,
    [userType_ID] int  NOT NULL
);
GO

-- Creating table 'SiteLibrary'
CREATE TABLE [SiteLibrary] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [name] nvarchar(40)  NULL,
    [value] nvarchar(4000)  NULL,
    [symbol] nvarchar(20)  NULL
);
GO

-- Creating table 'student'
CREATE TABLE [student] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [name] nvarchar(50)  NOT NULL,
    [exp] nvarchar(200)  NULL,
    [createDate] datetime  NOT NULL,
    [able] bit  NOT NULL,
    [password] nvarchar(4000)  NULL,
    [lastDate] datetime  NOT NULL,
    [bak] nvarchar(4000)  NULL,
    [studentClassID] int  NOT NULL,
    [innerData] nvarchar(4000)  NULL,
    [sex] bit  NOT NULL,
    [tel] nvarchar(4000)  NULL,
    [birthday] datetime  NULL,
    [address] nvarchar(4000)  NULL,
    [parents] nvarchar(4000)  NULL,
    [isOpen] bit  NOT NULL,
    [pic] nvarchar(4000)  NULL,
    [viewCount] int  NOT NULL
);
GO

-- Creating table 'studentClass'
CREATE TABLE [studentClass] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [name] nvarchar(4000)  NOT NULL,
    [bak] nvarchar(4000)  NULL,
    [able] bit  NOT NULL
);
GO

-- Creating table 'studentDaily'
CREATE TABLE [studentDaily] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [title] nvarchar(100)  NOT NULL,
    [able] bit  NOT NULL,
    [content] nvarchar(4000)  NULL,
    [createDate] nvarchar(4000)  NOT NULL,
    [studentID] int  NOT NULL,
    [studentDailyTypeID] int  NOT NULL,
    [teacherID] int  NULL,
    [tearcherName] nvarchar(4000)  NULL
);
GO

-- Creating table 'studentDailyType'
CREATE TABLE [studentDailyType] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [name] nvarchar(4000)  NOT NULL,
    [TempleteCode] nvarchar(4000)  NULL,
    [bak] nvarchar(4000)  NULL,
    [index] int  NOT NULL,
    [requirement] bit  NOT NULL
);
GO

-- Creating table 'studentReply'
CREATE TABLE [studentReply] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [content] nvarchar(4000)  NOT NULL,
    [createDate] datetime  NOT NULL,
    [lastDate] datetime  NOT NULL,
    [able] bit  NOT NULL,
    [isNew] bit  NOT NULL,
    [studentID] int  NOT NULL
);
GO

-- Creating table 'userType'
CREATE TABLE [userType] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [name] nvarchar(4000)  NOT NULL,
    [bak] nvarchar(4000)  NULL,
    [index] int  NOT NULL,
    [requirement] bit  NOT NULL
);
GO

-- Creating table 'studentViewLog'
CREATE TABLE [studentViewLog] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [ip] nvarchar(4000)  NOT NULL,
    [date] datetime  NOT NULL,
    [studentID] int  NOT NULL
);
GO

-- Creating table 'channel'
CREATE TABLE [channel] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [name] nvarchar(4000)  NOT NULL,
    [TempleteCode] nvarchar(4000)  NULL,
    [index] int  NOT NULL,
    [requirement] bit  NOT NULL,
    [bak] nvarchar(4000)  NULL,
    [createDate] datetime  NOT NULL,
    [able] bit  NOT NULL,
    [type] nvarchar(4000)  NULL,
    [exp] nvarchar(4000)  NULL,
    [postCount] int  NOT NULL,
    [parentID] int  NULL,
    [extUrl] nvarchar(4000)  NULL,
    [isNull] bit  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'document'
ALTER TABLE [document]
ADD CONSTRAINT [PK_document]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'documentType'
ALTER TABLE [documentType]
ADD CONSTRAINT [PK_documentType]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'guestBook'
ALTER TABLE [guestBook]
ADD CONSTRAINT [PK_guestBook]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'manageUser'
ALTER TABLE [manageUser]
ADD CONSTRAINT [PK_manageUser]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'SiteLibrary'
ALTER TABLE [SiteLibrary]
ADD CONSTRAINT [PK_SiteLibrary]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'student'
ALTER TABLE [student]
ADD CONSTRAINT [PK_student]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'studentClass'
ALTER TABLE [studentClass]
ADD CONSTRAINT [PK_studentClass]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'studentDaily'
ALTER TABLE [studentDaily]
ADD CONSTRAINT [PK_studentDaily]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'studentDailyType'
ALTER TABLE [studentDailyType]
ADD CONSTRAINT [PK_studentDailyType]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'studentReply'
ALTER TABLE [studentReply]
ADD CONSTRAINT [PK_studentReply]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'userType'
ALTER TABLE [userType]
ADD CONSTRAINT [PK_userType]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'studentViewLog'
ALTER TABLE [studentViewLog]
ADD CONSTRAINT [PK_studentViewLog]
    PRIMARY KEY ([ID] );
GO

-- Creating primary key on [ID] in table 'channel'
ALTER TABLE [channel]
ADD CONSTRAINT [PK_channel]
    PRIMARY KEY ([ID] );
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [documentTypeID] in table 'document'
ALTER TABLE [document]
ADD CONSTRAINT [FK_documentdocumentType]
    FOREIGN KEY ([documentTypeID])
    REFERENCES [documentType]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_documentdocumentType'
CREATE INDEX [IX_FK_documentdocumentType]
ON [document]
    ([documentTypeID]);
GO

-- Creating foreign key on [studentID] in table 'studentDaily'
ALTER TABLE [studentDaily]
ADD CONSTRAINT [FK_studentstudentDaily]
    FOREIGN KEY ([studentID])
    REFERENCES [student]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_studentstudentDaily'
CREATE INDEX [IX_FK_studentstudentDaily]
ON [studentDaily]
    ([studentID]);
GO

-- Creating foreign key on [studentDailyTypeID] in table 'studentDaily'
ALTER TABLE [studentDaily]
ADD CONSTRAINT [FK_studentDailystudentDailyType]
    FOREIGN KEY ([studentDailyTypeID])
    REFERENCES [studentDailyType]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_studentDailystudentDailyType'
CREATE INDEX [IX_FK_studentDailystudentDailyType]
ON [studentDaily]
    ([studentDailyTypeID]);
GO

-- Creating foreign key on [studentID] in table 'studentReply'
ALTER TABLE [studentReply]
ADD CONSTRAINT [FK_studentstudentReply]
    FOREIGN KEY ([studentID])
    REFERENCES [student]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_studentstudentReply'
CREATE INDEX [IX_FK_studentstudentReply]
ON [studentReply]
    ([studentID]);
GO

-- Creating foreign key on [studentClassID] in table 'student'
ALTER TABLE [student]
ADD CONSTRAINT [FK_studentstudentClass]
    FOREIGN KEY ([studentClassID])
    REFERENCES [studentClass]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_studentstudentClass'
CREATE INDEX [IX_FK_studentstudentClass]
ON [student]
    ([studentClassID]);
GO

-- Creating foreign key on [userType_ID] in table 'manageUser'
ALTER TABLE [manageUser]
ADD CONSTRAINT [FK_manageUseruserType]
    FOREIGN KEY ([userType_ID])
    REFERENCES [userType]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_manageUseruserType'
CREATE INDEX [IX_FK_manageUseruserType]
ON [manageUser]
    ([userType_ID]);
GO

-- Creating foreign key on [studentID] in table 'studentViewLog'
ALTER TABLE [studentViewLog]
ADD CONSTRAINT [FK_studentstudentViewLog]
    FOREIGN KEY ([studentID])
    REFERENCES [student]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_studentstudentViewLog'
CREATE INDEX [IX_FK_studentstudentViewLog]
ON [studentViewLog]
    ([studentID]);
GO

-- Creating foreign key on [parentID] in table 'channel'
ALTER TABLE [channel]
ADD CONSTRAINT [FK_channelchannel]
    FOREIGN KEY ([parentID])
    REFERENCES [channel]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_channelchannel'
CREATE INDEX [IX_FK_channelchannel]
ON [channel]
    ([parentID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------